package com.example.controller;

import com.example.common.Result;
import com.example.service.SttService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/stt")
public class SttController
{
    @Resource
    private SttService sttService;
    @PostMapping("/upload")
    public Result upload(MultipartFile file)
    {
        String fileName = file.getOriginalFilename();
        if(fileName.contains("."))
        {
            /**得到后缀名*/
            String suffixName=fileName.substring(fileName.lastIndexOf(".") + 1);
            /**后缀名判断*/
            if(suffixName.equals("wav")||suffixName.equals("pcm")||suffixName.equals("amr")||suffixName.equals("m4a"))
            {
                /**转文字并返回*/
                String txtData=sttService.m2t(file,"",suffixName);
                return Result.success(txtData);
            }
        }
        return Result.error("402","错误,上传的不是音频");
    }
}
